from PyQt5 import QtCore,QtWidgets,QtGui
from PyQt5.QtCore import QObject,QPropertyAnimation,QRect,QPoint
from PyQt5.QtWidgets import QWidget,QLabel,QVBoxLayout,QHBoxLayout,QAction,QWidgetAction,QPushButton,QMenu
from PyQt5.QtGui import QBrush,QIcon,QPixmap,QPainter,QFont,QFontMetrics,QColor

from Q360Button import *
import lowmainres
import trayiconmenures
import upmainres
import centerwindres

class level4Widget(QWidget):
    def __init__(self,parent=None):
        super(level4Widget, self).__init__(parent)
        vlayout = QVBoxLayout()
        vlayout1 = QVBoxLayout()
        hlayout = QHBoxLayout()
        m_btn = MainButton6(":/image/traymen/ico_360safe.png", "打开卫士");
        m_btn1 = MainButton6(":/image/traymen/ico_safecheck.png", "查杀修复");
        m_btn2 = MainButton6(":/image/traymen/ico_speed.png", "优化加速");
        m_btn3 = MainButton6(":/image/traymen/ico_examine.png", "电脑体检");
        m_btn4 = MainButton6(":/image/traymen/ico_clean.png", "电脑清理");
        m_btn5 = MainButton6(":/image/traymen/ico_softmgr.png", "软件管家");

        m_btn.setFixedSize(130, 92);
        m_btn1.setFixedSize(130, 92);
        m_btn2.setFixedSize(130, 92);
        m_btn3.setFixedSize(130, 92);
        m_btn4.setFixedSize(130, 92);
        m_btn5.setFixedSize(130, 92);

        vlayout.addWidget(m_btn)
        vlayout.addWidget(m_btn1)
        vlayout.addWidget(m_btn2)
        vlayout.setSpacing(1)

        vlayout1.addWidget(m_btn3)
        vlayout1.addWidget(m_btn4)
        vlayout1.addWidget(m_btn5)
        vlayout1.setSpacing(1)

        hlayout.addLayout(vlayout)
        hlayout.addLayout(vlayout1)
        hlayout.setSpacing(1)
        hlayout.setContentsMargins(0,0,0,0)
        self.setContentsMargins(0,0,0,0)
        self.setLayout(hlayout)
        self.setMaximumWidth(261)
        self.setMinimumWidth(261)

    def paintEvent(self, a0: QtGui.QPaintEvent):
        p = QPainter(self)
        p.setPen(QColor(235,235,235))
        p.drawLine(QPoint(self.width()/2+1,0),QPoint(self.width()/2,self.height()))
        p.drawLine(QPoint(0,self.height()/3),QPoint(self.width(),self.height()/3))
        p.drawLine(QPoint(0,self.height()*2/3),QPoint(self.width(),self.height()*2/3))
        p.drawLine(QPoint(0,self.height()-1),QPoint(self.width(),self.height()-1))

class level5Widget(QWidget):
    def __init__(self,parent=None):
        super(level5Widget, self).__init__(parent)
        self.setStyleSheet("border-image:url(:/image/traymen/bg_safe.png)")
        vlayout = QVBoxLayout()
        hlayout = QHBoxLayout()
        hlayout1 = QHBoxLayout()
        m_btn = MainButton3(":/image/traymen/ico_protect_opened.png",self)
        m_btn1 = MainButton3(":/image/traymen/ico_enter_safe_center.png",self)
        m_btn.setFixedSize(133,25)
        m_btn1.setFixedSize(28,16)
        hlayout.addWidget(m_btn,0,QtCore.Qt.AlignLeft)
        hlayout.addWidget(m_btn1,0,QtCore.Qt.AlignLeft)
        hlayout.setSpacing(30)
        hlayout.setContentsMargins(5,0,0,0)
        label = QLabel("360安全卫士已保护您的电脑365天")
        hlayout1.addWidget(label)
        hlayout1.setContentsMargins(6,0,0,0)
        #label.setStyleSheet("color:white")
        font = QFont()
        font.setBold(True)
        label.setFont(font)
        
        vlayout.addLayout(hlayout1)
        #vlayout.addLayout(hlayout)
        vlayout.setSpacing(0)
        self.setLayout(vlayout)
        
        self.setFixedSize(261,70)
        
    def paintEvent(self, a0: QtGui.QPaintEvent):
        super(level5Widget, self).paintEvent(a0)

class TrayIconMenu(QMenu):
    def __init__(self,parent=None):
        super(TrayIconMenu, self).__init__(parent)
        self.initlevel5();
        self.initlevel4();
        self.initlevel3();
        self.initlevel2();
        self.initlevel1();
        self.initlevel0();
        self.setStyleSheet("QMenu{border:NULL;background:white;color: rgb(88,88,88);}"
                      "QMenu::item{height:26px;background:white;}"
                      "QMenu::item::selected{background:white;background-color:rgb(242,242,242);}");


    def initlevel5(self):
        widaction = QWidgetAction(self)
        level5wid = level5Widget(self)

        widaction.setDefaultWidget(level5wid)
        self.addAction(widaction)
    def initlevel4(self):
        widaction = QWidgetAction(self)
        level4wid = level4Widget(self)

        widaction.setDefaultWidget(level4wid)
        self.addAction(widaction)
    def initlevel3(self):
        actionInfo = QAction(QIcon(":/image/traymen/ico_switchmode.png"),"游戏,网购模式",self)
        menuupdate = QMenu(self)
        actionappupdate = QAction(QIcon(":/image/traymen/ico_game_mode.png"),"进入游戏模式",self)
        actiondownloadmanager = QAction(QIcon(":/image/traymen/ico_netpay_mode.png"),"进入网购模式",self)

        menuupdate.addAction(actionappupdate)
        menuupdate.addAction(actiondownloadmanager)
        actionInfo.setMenu(menuupdate)
        self.addAction(actionInfo)
    def initlevel2(self):
        actionInfo = QAction(QIcon(":/image/traymen/ico_update.png"),"升级",self)
        menuupdate = QMenu(self)
        actionappupdate = QAction(QIcon(":/image/traymen/ico_update_item.png"), "程序升级", self);
        actiondownloadmanger = QAction(QIcon(":/image/traymen/ico_download_mgr.png"), "360下载管理", self);

        menuupdate.addAction(actionappupdate);
        menuupdate.addAction(actiondownloadmanger);
        actionInfo.setMenu(menuupdate);
        self.addAction(actionInfo);
    def initlevel1(self):
        actioninfo = QAction(QIcon(":/image/traymen/ico_safenotify.png"),"安全通知",self)
        self.addAction(actioninfo)
    def initlevel0(self):
        action = QWidgetAction(self)
        m_widlevel0 = QWidget(self)
        hyout = QHBoxLayout(m_widlevel0)

        m_btnsetting = MainButton3(":/image/traymen/button_setting.png",m_widlevel0)
        m_btnfeedback = MainButton3(":/image/traymen/button_feedback.png",m_widlevel0)
        m_btnexit = MainButton3(":/image/traymen/button_exit.png",m_widlevel0);

        m_btnsetting.setFixedSize(87,32)
        m_btnfeedback.setFixedSize(87,32)
        m_btnexit.setFixedSize(87,32)

        hyout.addWidget(m_btnsetting)
        hyout.addWidget(m_btnfeedback)
        hyout.addWidget(m_btnexit)
        hyout.setSpacing(0)
        hyout.setContentsMargins(0,0,0,0)
        m_widlevel0.setLayout(hyout)
        m_widlevel0.setMaximumWidth(261)
        m_widlevel0.setMinimumWidth(261)
        action.setDefaultWidget(m_widlevel0)
        m_widlevel0.setContentsMargins(0,0,0,0)
        m_widlevel0.setStyleSheet("QWidget{border-image:url(:/image/traymen/bg_safe.png);}")
        self.addAction(action)
    def paintEvent(self, a0: QtGui.QPaintEvent):
        super(TrayIconMenu, self).paintEvent(a0)





























